package com.android.launcher3.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.telephony.SubscriptionInfo;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.launcher3.R;
import com.x.component.bluetooth.BluetoothComponent;
import com.x.component.bluetooth.BluetoothTool;
import com.x.component.connectivity.ConnectivityComponent;
import com.x.component.connectivity.ConnectivityTool;
import com.x.component.connectivity.IconState;
import com.x.component.connectivity.MobileDataIndicators;
import com.x.component.connectivity.MobileState;
import com.x.component.connectivity.WifiIndicators;
import com.x.component.connectivity.WifiState;

import java.util.List;

public class BluetoothSettingItemWidget extends SettingItemWidget {

    private String TAG = "BluetoothSettingItemWidget";

    public BluetoothSettingItemWidget(@NonNull Context context) {
        super(context);
    }

    public BluetoothSettingItemWidget(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public BluetoothSettingItemWidget(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    private ImageView icon;
    private TextView tv_name;
    private TextView tv_sec_name;

    @Override
    void setUpView() {
        super.setUpView();
        icon = findViewById(R.id.icon);
        tv_name = findViewById(R.id.tv_name);
        tv_sec_name = findViewById(R.id.tv_sec_name);
        BluetoothComponent INSTANCE = BluetoothComponent.getInstance();
        INSTANCE.init(getContext());
        if (INSTANCE.getHfpState() == 1) {
            icon.setImageResource(R.drawable.ic_bluetooth_connected);
            tv_sec_name.setText(R.string.bluetooth_connected);
        } else {
            icon.setImageResource(R.drawable.ic_bluetooth_disconnect);
            tv_sec_name.setText(R.string.bluetooth_disconnected);
        }
        INSTANCE.setBluetoothTool(new BluetoothTool() {
            @Override
            public void onBTEnabledStateChanged(int enabled) {

            }

            @Override
            public void onHfpStateChanged(int state) {
                if (INSTANCE.getHfpState() == 1) {
                    icon.setImageResource(R.drawable.ic_bluetooth_connected);
                    tv_sec_name.setText(R.string.bluetooth_connected);
                } else {
                    icon.setImageResource(R.drawable.ic_bluetooth_disconnect);
                    tv_sec_name.setText(R.string.bluetooth_disconnected);
                }
            }
        });

    }
}